<?php

namespace App\Admin\Actions\ShopProduct;

use App\Library\Logic\OperateLogLogic;
use App\Library\Models\AdminShopProductModel;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;

class ShopProductDeleteAction extends RowAction
{
    public $name = '删除';

    /**
     * handle
     * @param AdminShopProductModel $model
     * @return Response
     */
    public function handle(AdminShopProductModel $model): Response
    {
        $model->deleted_at = now();
        $model->product_is_delete = 1;
        $model->save();
        OperateLogLogic::add(Admin::user()->user_id, 'admin.product.delete');
        return $this->response()->success('操作成功')->refresh();
    }

    public function dialog(): void
    {
        $this->confirm('确定删除吗?');
    }
}
